package com.swn.common.util;

import java.util.ArrayList;
import java.util.List;

//分页
public class PageListData{
	//查询的数据
    @SuppressWarnings("rawtypes")
	private List dataArray;
    //记录的个数
    private int count;
    //一页中显示的记录条数
    private int pageSize;
    //共有多少页
    private int pageCount;
    //第几页页码
    private int page;
    
    /** * mySql分页2个参数 */
    //开始的位置
    private int start;
    //显示的长度
    private int length;

    public PageListData()
    {
        dataArray = null;
        count = 0;
        pageSize = 10;
        pageCount = 0;
        page = 1;
        newDataArray();
    }

    @SuppressWarnings("rawtypes")
	public List getDataArray()
    {
        return dataArray;
    }

    @SuppressWarnings("rawtypes")
	public void setDataArray(List dataArray)
    {
        this.dataArray = dataArray;
    }

    public Object getData(int i)
    {
        return getDataArray().get(i);
    }

    @SuppressWarnings("rawtypes")
	public void newDataArray()
    {
        if(dataArray == null)
            dataArray = new ArrayList();
    }

    public void clearDataArray()
    {
        if(dataArray != null)
            dataArray.clear();
    }

    @SuppressWarnings("unchecked")
	public void addData(Object data)
    {
        newDataArray();
        getDataArray().add(data);
    }

    @SuppressWarnings("unchecked")
	public void addData(int i, Object data)
    {
        newDataArray();
        getDataArray().add(i, data);
    }

    public int getCount()
    {
        return count;
    }

    public void setCount(int count)
    {
        if(pageSize != 0)
        {
            pageCount = count / pageSize;
            if(count % pageSize != 0)
                pageCount++;
        }
        this.count = count;
    }

    public int getPageCount()
    {
        return pageCount;
    }

    public void setPageCount(int pageCount)
    {
        this.pageCount = pageCount;
    }

    public int getPageSize()
    {
        return pageSize;
    }

    public void setPageSize(int pageSize)
    {
        this.pageSize = pageSize;
    }

    public int getPage()
    {
        return page;
    }

    public void setPage(int page)
    {
        this.page = page;
    }
    
    

    /*public String getFooter(int pageType)
    {
        StringBuffer str = new StringBuffer("");
        int prev = page - 1;
        int next = page + 1;
        
        if(pageType==0) { //pageType==0：首页 、上页、下页、尾页显示为按钮；否则显示为超链接字体
        if(page > 1)
            str.append("<INPUT type=submit class=button value=首页 name=firs onclick='this.form.pages.value=1'>");
        else
            str.append("<INPUT type=submit class=button value=首页 name=firs disabled>");
        if(page > 1)
            str.append("&nbsp;<INPUT type=submit class=button value=上页 name=prev onclick='this.form.pages.value=" + prev + "'>");
        else
            str.append("&nbsp;<INPUT type=submit class=button value=上页 name=prev disabled>");
        if(page < pageCount)
            str.append("&nbsp;<INPUT type=submit class=button value=下页 name=next onclick='this.form.pages.value=" + next + "'>");
        else
            str.append("&nbsp;<INPUT type=submit class=button value=下页 name=next disabled>");
        if(pageCount > 1 && page != pageCount)
            str.append("&nbsp;<INPUT type=submit class=button value=末页 name=last onclick='this.form.pages.value=" + pageCount + "'>");
        else
            str.append("&nbsp;<INPUT type=submit class=button value=末页 name=last disabled>");
        str.append(" 共" + getCount() + "条记录");
        str.append("  每页<SELECT size=1 name=pagesize onchange='this.form.pages.value=1;this.form.pageSize.value=this.value;this.form.submit();'>");
        
        if(pageSize == 10)
            str.append("<OPTION value=10 selected>10</OPTION>");
        else
            str.append("<OPTION value=10>10</OPTION>");
        if(pageSize == 20)
            str.append("<OPTION value=20 selected>20</OPTION>");
        else
            str.append("<OPTION value=20>20</OPTION>");
        if(pageSize == 50)
            str.append("<OPTION value=50 selected>50</OPTION>");
        else
            str.append("<OPTION value=50>50</OPTION>");
        if(pageSize == 80)
            str.append("<OPTION value=80 selected>80</OPTION>");
        else
            str.append("<OPTION value=80>80</OPTION>");
        if(pageSize == 100)
            str.append("<OPTION value=100 selected>100</OPTION>");
        else
            str.append("<OPTION value=100>100</OPTION>");
        if(pageSize == 200)
            str.append("<OPTION value=200 selected>200</OPTION>");
        else
            str.append("<OPTION value=200>200</OPTION>");
        str.append("</SELECT>");
        str.append("条 当前第").append(page).append("页 共" + pageCount + "页").append(" 转到");
        str.append("<SELECT size=1 name=Pagelist onchange='this.form.pages.value=this.value;this.form.submit();'>");
        for(int i = 1; i < pageCount + 1; i++)
            if(i == page)
                str.append("<OPTION value=" + i + " selected>" + i + "</OPTION>");
            else
                str.append("<OPTION value=" + i + ">" + i + "</OPTION>");

        str.append("</SELECT>页");
        str.append("<INPUT type=hidden  value=" + page + " name=\"pages\" > ");
        str.append("<INPUT type=hidden  value=" + pageSize + " name=\"pageSize\"> ");
        }
        else
        {
       	 str.append("当前第").append(page).append("页/共").append(pageCount).append("页 共").append(getCount()).append("条记录 		");
            if(page > 1)
                str.append("<a style=\"cursor:hand\" onclick='document.forms[0].pages.value=1;document.forms[0].submit();'><U>首页</U></a>");
            else
                str.append("首页");
            if(page > 1)
                str.append("&nbsp;<a style=\"cursor:hand\" onclick='document.forms[0].pages.value=" + prev + ";document.forms[0].submit();'><U>上页</U></a>");
            else
                str.append("&nbsp;上页");
            
            if(page < pageCount)
            	 str.append("&nbsp;<a style=\"cursor:hand\" href='#' onclick='document.forms[0].pages.value=" + next + ";document.forms[0].submit();'><U>下页</U></a>");
            else
            	 str.append("&nbsp;下页");
            if(pageCount > 1 && page != pageCount)
            	 str.append("&nbsp;<a style=\"cursor:hand\" onclick='document.forms[0].pages.value=" + pageCount + ";document.forms[0].submit();'><U>尾页</U></a>");
            else
            	 str.append("&nbsp;尾页");
            str.append("	转到第");
            str.append("<SELECT size=1 name=Pagelist onchange='this.form.pages.value=this.value;document.forms[0].submit();'>");
            for(int i = 1; i < pageCount + 1; i++)
                if(i == page)
                    str.append("<OPTION value=" + i + " selected>" + i + "</OPTION>");
                else
                    str.append("<OPTION value=" + i + ">" + i + "</OPTION>");

            str.append("</SELECT>页");
            str.append("<INPUT type=hidden  value=" + page + " name=\"pages\" > ");
            str.append("<INPUT type=hidden  value=" + pageSize + " name=\"pageSize\"> ");
       }
        return str.toString();
    }*/

    /*@Override
	public String toString()
    {
        return getFooter(0);
    }*/

    public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	@SuppressWarnings("rawtypes")
	public List getCurPageList()
    {
        return dataArray;
    }

    @SuppressWarnings("rawtypes")
	public void setCurPageList(List dataArray)
    {
        this.dataArray = dataArray;
    }
}
